<template lang="pug">
    .pug-container()
        InterpolationDialog(@map:event="mapEvent")
</template>

<script lang="ts">
import InterpolationDialog from '../../components/dialog/interpolation/InterpolationDialog.vue';
import { Vue, Component } from 'vue-property-decorator';
import { MapTypeEnum } from '@/map/type/CommonType';
import CesiumService from '@/map/service/CesiumService';
import LeafletService from '@/map/service/LeafletService';
import MapBoxService from '@/map/service/MapBoxService';
import { namespace } from 'vuex-class';
import { Color, GeoJsonDataSource, SingleTileImageryProvider, Rectangle, Math as CesiumMath, Camera } from 'cesium';
import L, { LatLngBoundsExpression } from 'leaflet';
import loadingPluginService from '../../puglin/LoadingPluginService';
const appModule = namespace('appModule');
// @ts-ignore
// const kriging = require('../../map/service/cesium/plugin/kriging.min.js');
const bounds = [[[121.9043, 25.0488], [121.9922, 25.0049], [121.8164, 24.7412], [121.9043, 24.5654], [121.6406, 24.0381], [121.377, 23.1152], [121.0254, 22.6758], [120.8496, 22.0605], [120.7617, 21.9287], [120.6738, 22.3242], [120.2344, 22.5879], [120.0586, 23.0713], [120.1465, 23.6865], [121.0254, 25.0488], [121.5527, 25.3125], [121.9043, 25.0488]],[[123.662100000000351, 53.569300000000169], [124.892600000000471, 53.0859], [125.0684, 53.217800000000182], [125.59570000000042, 53.0859], [125.683600000000183, 52.910200000000316], [126.123000000000502, 52.778300000000286], [126.035200000000486, 52.602500000000248], [126.210900000000265, 52.5146], [126.386700000000246, 52.294900000000212], [126.386700000000246, 52.207000000000278], [126.562500000000114, 52.16310000000027], [126.474600000000237, 51.943400000000224], [126.9141, 51.372100000000216], [126.826200000000199, 51.284200000000283], [127.00200000000018, 51.32810000000029], [126.9141, 51.108400000000188], [127.265600000000177, 50.756800000000283], [127.353500000000281, 50.273400000000208], [127.617200000000253, 50.229500000000201], [127.529300000000262, 49.877900000000238], [127.793000000000347, 49.614300000000185], [128.759800000000268, 49.570300000000259], [129.111300000000483, 49.350600000000156], [129.4629, 49.438500000000261], [130.253900000000158, 48.867200000000253], [130.693400000000224, 48.867200000000253], [130.517600000000243, 48.647500000000207], [130.869100000000344, 48.295900000000245], [130.693400000000224, 48.120100000000207], [131.044900000000212, 47.680700000000229], [132.53910000000019, 47.724600000000237], [132.627000000000294, 47.944300000000169], [133.066400000000272, 48.120100000000207], [133.505900000000224, 48.120100000000207], [134.209000000000287, 48.383800000000235], [135.087900000000218, 48.427700000000243], [134.736300000000256, 48.252000000000237], [134.560500000000275, 47.988300000000265], [134.736300000000256, 47.680700000000229], [134.560500000000275, 47.460900000000265], [134.384800000000155, 47.460900000000265], [134.209000000000287, 47.285200000000316], [134.209000000000287, 47.153300000000229], [133.857400000000325, 46.538100000000213], [133.945300000000202, 46.274400000000242], [133.505900000000224, 45.835000000000264], [133.41800000000012, 45.571300000000292], [133.242200000000139, 45.527300000000196], [133.066400000000272, 45.131800000000226], [132.890600000000177, 45.043900000000292], [131.923800000000256, 45.35160000000019], [131.572300000000155, 45.043900000000292], [131.044900000000212, 44.868200000000172], [131.308600000000411, 44.077100000000144], [131.220700000000193, 43.725600000000156], [131.308600000000411, 43.461900000000298], [131.308600000000411, 43.330100000000186], [131.1328, 42.934600000000216], [130.429700000000139, 42.714800000000253], [130.6055, 42.670900000000245], [130.6055, 42.451200000000142], [130.253900000000158, 42.758800000000178], [130.253900000000158, 42.89060000000029], [130.166, 42.978500000000224], [129.902300000000196, 43.02250000000015], [129.7266, 42.49510000000015], [129.375000000000227, 42.451200000000142], [128.935500000000161, 42.011700000000303], [128.05660000000023, 42.011700000000303], [128.3203, 41.572300000000155], [128.144500000000107, 41.352500000000134], [127.089800000000196, 41.528300000000229], [127.1777, 41.572300000000155], [126.9141, 41.792000000000201], [126.650400000000332, 41.660200000000259], [126.474600000000237, 41.396500000000287], [126.123000000000502, 40.957000000000221], [125.683600000000183, 40.869100000000287], [124.541000000000167, 40.210000000000264], [124.10160000000019, 39.682600000000264], [123.398400000000265, 39.682600000000264], [123.134800000000268, 39.418900000000235], [123.134800000000268, 39.0234], [122.080100000000357, 39.0234], [121.552700000000186, 38.715800000000286], [121.113300000000208, 38.671900000000278], [120.937500000000341, 38.979500000000314], [121.377000000000407, 39.199200000000189], [121.2012, 39.5508], [122.080100000000357, 40.385700000000213], [121.992200000000253, 40.693400000000111], [121.728500000000167, 40.825200000000279], [121.2012, 40.825200000000279], [120.585900000000152, 40.210000000000264], [119.882800000000202, 39.946300000000235], [119.5313, 39.682600000000264], [119.443400000000224, 39.418900000000235], [118.916, 39.067400000000248], [118.47660000000019, 38.935500000000161], [118.125000000000227, 39.0234], [118.037100000000123, 39.199200000000189], [117.861300000000256, 39.111300000000256], [117.597700000000259, 38.627900000000182], [117.94920000000036, 38.320300000000145], [118.125000000000227, 38.144500000000278], [118.916, 38.144500000000278], [119.35550000000012, 37.661100000000204], [119.003900000000272, 37.529300000000262], [119.003900000000272, 37.353500000000224], [119.35550000000012, 37.133800000000292], [119.707000000000221, 37.133800000000292], [119.882800000000202, 37.39750000000015], [120.498000000000275, 37.836900000000298], [120.585900000000152, 38.144500000000278], [120.937500000000341, 38.4521], [121.025400000000218, 37.836900000000298], [121.2012, 37.661100000000204], [121.9043, 37.485400000000254], [122.168000000000234, 37.617200000000196], [122.255900000000224, 37.485400000000254], [122.607400000000439, 37.485400000000254], [122.695300000000202, 37.353500000000224], [122.607400000000439, 36.914100000000246], [122.431600000000117, 36.782200000000216], [121.816400000000272, 36.87010000000015], [121.728500000000167, 36.694300000000283], [121.113300000000208, 36.606400000000292], [121.113300000000208, 36.430700000000172], [121.377000000000407, 36.254900000000305], [120.7617, 36.167000000000201], [120.937500000000341, 35.859400000000164], [120.673800000000256, 36.035200000000259], [119.707000000000221, 35.463900000000251], [119.970700000000193, 34.980500000000177], [119.35550000000012, 35.024400000000185], [119.35550000000012, 34.84860000000026], [119.707000000000221, 34.585000000000207], [120.322300000000155, 34.365200000000243], [120.937500000000341, 33.046900000000221], [121.025400000000218, 32.651400000000308], [121.377000000000407, 32.475600000000213], [121.464800000000423, 32.168000000000234], [121.9043, 31.992200000000196], [121.992200000000253, 31.68460000000016], [121.992200000000253, 31.596700000000226], [121.9043, 31.157200000000159], [121.992200000000253, 30.805700000000172], [122.695300000000202, 30.893600000000276], [122.871100000000183, 30.717800000000182], [122.959000000000287, 30.146500000000174], [122.607400000000439, 30.102500000000248], [122.607400000000439, 29.926800000000298], [122.168000000000234, 29.531300000000158], [122.343800000000101, 28.872100000000216], [121.992200000000253, 28.872100000000216], [121.992200000000253, 28.43260000000015], [121.728500000000167, 28.344700000000216], [121.728500000000167, 28.212900000000275], [121.464800000000423, 28.212900000000275], [121.552700000000186, 28.037100000000237], [121.289100000000303, 27.949200000000303], [121.113300000000208, 27.421900000000221], [120.673800000000256, 27.334000000000287], [120.673800000000256, 27.158200000000193], [120.937500000000341, 27.026400000000251], [120.7617, 27.026400000000251], [120.673800000000256, 26.894500000000221], [120.234400000000392, 26.850600000000213], [120.234400000000392, 26.718800000000272], [120.410200000000259, 26.674800000000118], [120.498000000000275, 26.36720000000031], [120.234400000000392, 26.279300000000205], [120.410200000000259, 26.147500000000264], [120.0586, 26.191400000000272], [119.970700000000193, 25.927700000000243], [119.794900000000325, 25.927700000000243], [119.970700000000193, 25.400400000000161], [119.794900000000325, 25.26860000000022], [119.5313, 25.136700000000189], [119.443400000000224, 25.004900000000248], [119.267600000000243, 25.092800000000182], [118.916, 24.829100000000153], [118.652300000000309, 24.521500000000174], [118.47660000000019, 24.521500000000174], [118.47660000000019, 24.43360000000024], [118.212900000000104, 24.345700000000306], [118.212900000000104, 24.169900000000212], [117.861300000000256, 23.994100000000174], [117.7734, 23.774400000000298], [117.509800000000155, 23.598600000000204], [117.158200000000193, 23.554700000000196], [117.334000000000515, 23.247100000000216], [116.894500000000107, 23.378900000000158], [116.630900000000224, 23.115200000000129], [116.543, 22.851600000000246], [115.9277, 22.719700000000216], [115.6641, 22.763700000000142], [115.576200000000313, 22.631800000000283], [115.048800000000483, 22.675800000000208], [114.609400000000278, 22.368200000000172], [114.345700000000193, 22.543900000000122], [113.99410000000023, 22.500000000000114], [113.818400000000452, 22.192400000000305], [114.345700000000193, 22.148400000000208], [114.433600000000297, 22.016600000000267], [114.082000000000107, 21.928700000000106], [113.99410000000023, 21.796900000000164], [113.554700000000253, 22.016600000000267], [113.1152, 21.840800000000172], [112.93950000000018, 21.5771000000002], [112.412100000000237, 21.445300000000259], [112.2363, 21.533200000000193], [111.533200000000193, 21.489300000000185], [111.269500000000221, 21.3574], [110.74220000000031, 21.3574], [110.654300000000205, 21.225600000000156], [110.74220000000031, 20.918000000000177], [110.478500000000111, 20.874000000000251], [110.654300000000205, 20.258800000000235], [111.093800000000272, 19.951200000000199], [111.269500000000221, 19.995100000000207], [110.654300000000205, 19.160200000000145], [110.566400000000272, 18.676800000000242], [110.214800000000139, 18.588900000000308], [110.03910000000019, 18.369100000000117], [109.8633, 18.369100000000117], [109.687500000000227, 18.105500000000234], [108.984400000000278, 18.281300000000101], [108.632800000000145, 18.457000000000221], [108.632800000000145, 19.379900000000191], [109.072300000000212, 19.64360000000022], [109.248000000000161, 19.951200000000199], [109.599600000000294, 20.039100000000303], [110.03910000000019, 20.127000000000237], [109.8633, 20.127000000000237], [109.8633, 20.302700000000243], [109.599600000000294, 20.918000000000177], [109.775400000000161, 21.401400000000251], [109.599600000000294, 21.445300000000259], [109.160200000000316, 21.3574], [109.248000000000161, 20.874000000000251], [109.072300000000212, 20.961900000000185], [109.072300000000212, 21.533200000000193], [108.7207, 21.533200000000193], [108.632800000000145, 21.665000000000305], [108.281300000000158, 21.489300000000185], [107.841800000000262, 21.621100000000297], [107.402300000000196, 21.621100000000297], [107.050800000000208, 21.796900000000164], [107.050800000000208, 21.928700000000106], [106.699200000000246, 22.016600000000267], [106.611300000000313, 22.41210000000018], [106.78710000000018, 22.763700000000142], [106.699200000000246, 22.895500000000254], [105.908200000000193, 22.93950000000018], [105.55660000000023, 23.071300000000122], [105.55660000000023, 23.20310000000029], [105.293000000000177, 23.378900000000158], [104.853500000000281, 23.159200000000283], [104.765600000000177, 22.851600000000246], [104.326200000000199, 22.675800000000208], [104.150400000000161, 22.80760000000015], [103.974600000000237, 22.543900000000122], [103.623000000000161, 22.763700000000142], [103.535200000000316, 22.587900000000275], [103.359400000000221, 22.80760000000015], [103.095700000000249, 22.456100000000106], [102.480500000000234, 22.763700000000142], [102.304700000000196, 22.41210000000018], [101.8652000000003, 22.368200000000172], [101.777300000000196, 22.500000000000114], [101.60160000000019, 22.192400000000305], [101.8652000000003, 21.621100000000297], [101.777300000000196, 21.137700000000223], [101.60160000000019, 21.225600000000156], [101.250000000000284, 21.18160000000023], [101.16210000000018, 21.752900000000238], [100.634800000000268, 21.445300000000259], [100.107400000000268, 21.489300000000185], [99.931600000000174, 22.060500000000275], [99.228500000000224, 22.148400000000208], [99.404300000000319, 22.587900000000275], [99.316400000000158, 22.719700000000216], [99.492200000000253, 23.071300000000122], [98.877000000000237, 23.20310000000029], [98.701200000000142, 23.950200000000166], [98.877000000000237, 24.126000000000204], [98.173800000000142, 24.082000000000278], [97.734400000000221, 23.862300000000232], [97.558600000000126, 23.906300000000158], [97.734400000000221, 24.126000000000204], [97.646500000000287, 24.43360000000024], [97.558600000000126, 24.43360000000024], [97.558600000000126, 24.741200000000219], [97.734400000000221, 24.829100000000153], [97.822300000000155, 25.26860000000022], [98.173800000000142, 25.400400000000161], [98.173800000000142, 25.620100000000264], [98.349600000000237, 25.576200000000256], [98.525400000000275, 25.839800000000309], [98.701200000000142, 25.883800000000235], [98.613300000000208, 26.059600000000103], [98.701200000000142, 26.147500000000264], [98.789100000000303, 26.586900000000185], [98.701200000000142, 27.509800000000155], [98.525400000000275, 27.641600000000267], [98.349600000000237, 27.509800000000155], [98.173800000000142, 28.125000000000171], [97.558600000000126, 28.520500000000141], [97.294900000000155, 28.081100000000163], [97.382800000000259, 27.905300000000295], [97.031300000000272, 27.729500000000201], [96.503900000000272, 28.125000000000171], [95.712900000000161, 28.256800000000283], [95.361300000000256, 28.125000000000171], [95.2734, 27.949200000000303], [94.218800000000158, 27.553700000000163], [93.867200000000196, 27.026400000000251], [93.603500000000224, 26.938500000000147], [92.109400000000164, 26.850600000000213], [92.021500000000231, 27.465800000000229], [91.582000000000164, 27.553700000000163], [91.582000000000164, 27.905300000000295], [91.406300000000215, 28.037100000000237], [91.054700000000253, 27.861300000000142], [90.703100000000177, 28.081100000000163], [89.824200000000303, 28.212900000000275], [89.648400000000265, 28.168900000000178], [89.121100000000183, 27.597700000000259], [89.121100000000183, 27.334000000000287], [89.033200000000249, 27.2021000000002], [88.769500000000221, 27.421900000000221], [88.857400000000212, 27.993200000000229], [88.681600000000287, 28.125000000000171], [88.154300000000205, 27.905300000000295], [87.890600000000234, 27.949200000000303], [87.714800000000196, 27.817400000000134], [87.09960000000018, 27.817400000000134], [86.748000000000218, 28.125000000000171], [86.572300000000268, 28.125000000000171], [86.484400000000164, 27.905300000000295], [86.132800000000202, 28.125000000000171], [86.044900000000268, 27.905300000000295], [85.693400000000224, 28.344700000000216], [85.605500000000291, 28.256800000000283], [85.166000000000224, 28.344700000000216], [85.166000000000224, 28.652300000000253], [84.902300000000253, 28.564500000000237], [84.462900000000275, 28.740200000000186], [84.287100000000237, 28.872100000000216], [84.199200000000303, 29.22360000000026], [84.111300000000142, 29.267600000000186], [83.584000000000287, 29.179700000000253], [83.232400000000155, 29.575200000000166], [82.177700000000243, 30.05860000000024], [82.089800000000139, 30.322300000000268], [81.386700000000189, 30.366200000000276], [81.2109, 30.014600000000144], [81.035200000000316, 30.234400000000164], [80.068400000000224, 30.585900000000152], [79.716800000000262, 30.937500000000284], [79.013700000000142, 31.069300000000226], [78.750000000000284, 31.333000000000197], [78.837900000000275, 31.596700000000226], [78.66210000000018, 31.816400000000272], [78.750000000000284, 31.904300000000205], [78.486300000000313, 32.124000000000308], [78.398400000000208, 32.519500000000221], [78.750000000000284, 32.695300000000145], [78.925800000000208, 32.343800000000272], [79.277300000000196, 32.563500000000204], [79.101600000000246, 33.178700000000219], [78.66210000000018, 33.662100000000237], [78.66210000000018, 34.101600000000303], [78.925800000000208, 34.145500000000141], [79.013700000000142, 34.321300000000235], [78.222700000000259, 34.716800000000148], [78.046900000000164, 35.24410000000023], [78.046900000000164, 35.507800000000259], [77.43160000000023, 35.463900000000251], [76.816400000000215, 35.6396000000002], [76.552700000000243, 35.859400000000164], [76.201200000000199, 35.815400000000238], [75.937500000000227, 36.035200000000259], [76.025400000000161, 36.47460000000018], [75.849600000000237, 36.694300000000283], [75.498000000000161, 36.738300000000208], [75.410200000000316, 36.958000000000254], [75.058600000000183, 37.00200000000018], [74.882800000000145, 36.914100000000246], [74.794900000000212, 37.045900000000188], [74.531300000000272, 37.089800000000196], [74.531300000000272, 37.221700000000283], [74.882800000000145, 37.221700000000283], [75.146500000000287, 37.441400000000158], [74.882800000000145, 37.57320000000027], [74.970700000000249, 37.749000000000308], [74.882800000000145, 38.4521], [74.355500000000234, 38.671900000000278], [74.179700000000196, 38.671900000000278], [74.091800000000205, 38.540000000000248], [73.828100000000234, 38.584000000000174], [73.7402000000003, 38.847700000000316], [73.828100000000234, 38.979500000000314], [73.47660000000019, 39.375000000000227], [73.916000000000167, 39.506800000000169], [73.916000000000167, 39.682600000000264], [73.828100000000234, 39.770500000000197], [74.003900000000272, 40.034200000000169], [74.882800000000145, 40.341800000000205], [74.794900000000212, 40.517600000000243], [75.234400000000221, 40.42970000000031], [75.585900000000265, 40.649400000000185], [75.761700000000303, 40.297900000000197], [76.377000000000237, 40.385700000000213], [76.904300000000319, 41.001000000000147], [77.607400000000268, 41.001000000000147], [78.134800000000268, 41.220700000000193], [78.134800000000268, 41.396500000000287], [80.156300000000158, 42.055700000000229], [80.244100000000174, 42.275400000000275], [80.156300000000158, 42.627000000000237], [80.244100000000174, 42.846700000000283], [80.507800000000145, 42.89060000000029], [80.419900000000212, 43.066400000000158], [80.771500000000174, 43.198200000000156], [80.419900000000212, 44.165000000000248], [80.419900000000212, 44.604500000000314], [79.980500000000291, 44.824200000000189], [79.980500000000291, 44.956100000000276], [81.7383, 45.395500000000197], [82.089800000000139, 45.219700000000159], [82.529300000000205, 45.219700000000159], [82.265600000000177, 45.659200000000226], [83.056600000000287, 47.241200000000219], [83.671900000000221, 47.021500000000287], [84.726600000000303, 47.021500000000287], [84.902300000000253, 46.889600000000257], [85.517600000000186, 47.065400000000295], [85.693400000000224, 47.285200000000316], [85.517600000000186, 48.120100000000207], [85.781300000000158, 48.427700000000243], [86.572300000000268, 48.559600000000273], [86.835900000000152, 48.823200000000156], [86.748000000000218, 48.955100000000243], [86.835900000000152, 49.130900000000281], [87.8027000000003, 49.174800000000289], [87.890600000000234, 48.999000000000251], [87.714800000000196, 48.91110000000026], [88.066400000000272, 48.735400000000311], [87.978500000000167, 48.603500000000281], [88.505900000000167, 48.383800000000235], [88.681600000000287, 48.164100000000303], [89.121100000000183, 47.988300000000265], [89.560500000000161, 48.032200000000273], [89.736300000000199, 47.856400000000235], [90.087900000000161, 47.856400000000235], [90.351600000000303, 47.680700000000229], [90.527300000000253, 47.241200000000219], [90.878900000000215, 46.977500000000191], [91.054700000000253, 46.582000000000221], [90.878900000000215, 46.318400000000167], [91.054700000000253, 46.010700000000213], [90.703100000000177, 45.74710000000016], [90.703100000000177, 45.527300000000196], [90.878900000000215, 45.219700000000159], [91.582000000000164, 45.087900000000218], [93.51560000000029, 44.956100000000276], [94.74610000000024, 44.340800000000172], [95.361300000000256, 44.296900000000164], [95.361300000000256, 44.033200000000306], [95.537100000000294, 43.901400000000194], [95.888700000000256, 43.242200000000253], [96.328100000000177, 42.934600000000216], [96.416000000000111, 42.758800000000178], [96.416000000000111, 42.714800000000253], [97.207000000000221, 42.802700000000186], [99.492200000000253, 42.583000000000141], [100.810500000000218, 42.670900000000245], [101.777300000000196, 42.49510000000015], [102.041000000000167, 42.231400000000178], [102.744100000000287, 42.143600000000163], [103.359400000000221, 41.879900000000134], [103.886700000000303, 41.792000000000201], [104.502000000000237, 41.879900000000134], [104.502000000000237, 41.660200000000259], [105.029300000000319, 41.572300000000155], [105.732400000000268, 41.923800000000142], [107.402300000000196, 42.451200000000142], [109.423800000000256, 42.451200000000142], [110.390600000000177, 42.758800000000178], [111.005900000000111, 43.330100000000186], [111.972700000000259, 43.681600000000174], [111.972700000000259, 43.813500000000261], [111.445300000000259, 44.384800000000268], [111.796900000000221, 45.000000000000284], [111.972700000000259, 45.087900000000218], [113.64260000000013, 44.736300000000256], [114.169900000000212, 44.956100000000276], [114.5215, 45.395500000000197], [115.6641, 45.43950000000018], [116.191400000000499, 45.703100000000234], [116.279300000000262, 45.966800000000205], [116.543, 46.274400000000242], [117.334000000000515, 46.362300000000175], [117.421900000000278, 46.582000000000221], [117.7734, 46.538100000000213], [118.300800000000208, 46.757800000000145], [118.740200000000186, 46.713900000000308], [118.916, 46.757800000000145], [119.091800000000376, 46.669900000000212], [119.707000000000221, 46.626000000000204], [119.970700000000193, 46.713900000000308], [119.707000000000221, 47.197300000000212], [118.47660000000019, 47.988300000000265], [117.861300000000256, 48.032200000000273], [117.334000000000515, 47.680700000000229], [116.806600000000344, 47.900400000000161], [116.191400000000499, 47.856400000000235], [115.9277, 47.680700000000229], [115.576200000000313, 47.900400000000161], [115.488300000000208, 48.164100000000303], [115.839800000000196, 48.252000000000237], [115.839800000000196, 48.559600000000273], [116.718800000000329, 49.834000000000231], [117.7734, 49.526400000000251], [118.564500000000294, 49.921900000000164], [119.267600000000243, 50.097700000000259], [119.35550000000012, 50.317400000000305], [119.179700000000139, 50.361300000000313], [119.5313, 50.756800000000283], [119.5313, 50.888700000000142], [119.707000000000221, 51.06450000000018], [120.146500000000287, 51.679700000000196], [120.673800000000256, 51.943400000000224], [120.7617, 52.119100000000174], [120.7617, 52.251000000000204], [120.585900000000152, 52.338900000000308], [120.673800000000256, 52.5146], [120.410200000000259, 52.646500000000174], [120.0586, 52.602500000000248], [120.0586, 52.734400000000278], [120.849600000000237, 53.261700000000189], [121.464800000000423, 53.349600000000294], [123.662100000000351, 53.569300000000169]]];
let layers: any = {
    cesiumBoundsGeo: null,
    interpolationCesiumLayer: null,   // cesium 温度插值图层
    temptureLayerCesium: null, // cesium 温度插值

    mapboxBoundsGeo: null,
    interpolationMapboxLayer: null,   // cesium 温度插值图层
    temptureLayerMapbox: null, // cesium 温度插值

    temptureLayerUrlData: null,

    interpolationLeafletLayer: null,   // cesium 温度插值图层
};
type InterpolationType = 'TEMPERATURE_CHAIN' | 'WATER_LEVEL_HZ';
const kriging = (window as any).kriging;
@Component({
    components: {
        InterpolationDialog
    }
})
export default class InterpolationPage extends Vue {

    public loading: any = false;

    @appModule.State
    public mapType!: MapTypeEnum;

    @appModule.State
    private cesiumMapInstance!: CesiumService;

    @appModule.State
    private leafletMapInstance!: LeafletService;

    @appModule.State
    private mapBoxMapInstance!: MapBoxService;

    @appModule.Mutation
    private setMapType!: (number: MapTypeEnum) => void;

    /************************************  Cesium  ***********************************************************/

    public async loadKriging(): Promise<HTMLCanvasElement> {
        let canvas: HTMLCanvasElement = document.getElementById("cesiumCanvasMap") as HTMLCanvasElement;
        if (!canvas) {
            canvas = document.createElement('canvas');
        }
        canvas.width = 2000;
        canvas.height = 2000;
        const tempture: any[] = await import('../../map/service/cesium/data/mocktTempture.json');
        // const bounds: any = await import('../../map/service/cesium/data/bounds.json');
        const n = tempture.length;
        const t = [];
        const x = [];
        const y = [];
        for (let i = 0; i < n; i++) {
            t.push(tempture[i].properties.Temperatur); // 权重值
            x.push(tempture[i].geometry.coordinates[0]); // x
            y.push(tempture[i].geometry.coordinates[1]); // y
        }
        const variogram = kriging.train(t, x, y, "exponential", 0, 100);

        const grid = kriging.grid(bounds, variogram, 0.05);

        const colors = ["#00A600", "#01A600", "#03A700", "#04A700", "#05A800", "#07A800", "#08A900", "#09A900", "#0BAA00", "#0CAA00", "#0DAB00", "#0FAB00", "#10AC00", "#12AC00", "#13AD00", "#14AD00", "#16AE00", "#17AE00", "#19AF00", "#1AAF00", "#1CB000", "#1DB000", "#1FB100", "#20B100", "#22B200", "#23B200", "#25B300", "#26B300", "#28B400", "#29B400", "#2BB500", "#2CB500", "#2EB600", "#2FB600", "#31B700", "#33B700", "#34B800", "#36B800", "#37B900", "#39B900", "#3BBA00", "#3CBA00", "#3EBB00", "#3FBB00", "#41BC00", "#43BC00", "#44BD00", "#46BD00", "#48BE00", "#49BE00", "#4BBF00", "#4DBF00", "#4FC000", "#50C000", "#52C100", "#54C100", "#55C200", "#57C200", "#59C300", "#5BC300", "#5DC400", "#5EC400", "#60C500", "#62C500", "#64C600", "#66C600", "#67C700", "#69C700", "#6BC800", "#6DC800", "#6FC900", "#71C900", "#72CA00", "#74CA00", "#76CB00", "#78CB00", "#7ACC00", "#7CCC00", "#7ECD00", "#80CD00", "#82CE00", "#84CE00", "#86CF00", "#88CF00", "#8AD000", "#8BD000", "#8DD100", "#8FD100", "#91D200", "#93D200", "#95D300", "#97D300", "#9AD400", "#9CD400", "#9ED500", "#A0D500", "#A2D600", "#A4D600", "#A6D700", "#A8D700", "#AAD800", "#ACD800", "#AED900", "#B0D900", "#B2DA00", "#B5DA00", "#B7DB00", "#B9DB00", "#BBDC00", "#BDDC00", "#BFDD00", "#C2DD00", "#C4DE00", "#C6DE00", "#C8DF00", "#CADF00", "#CDE000", "#CFE000", "#D1E100", "#D3E100", "#D6E200", "#D8E200", "#DAE300", "#DCE300", "#DFE400", "#E1E400", "#E3E500", "#E6E600", "#E6E402", "#E6E204", "#E6E105", "#E6DF07", "#E6DD09", "#E6DC0B", "#E6DA0D", "#E6D90E", "#E6D710", "#E6D612", "#E7D414", "#E7D316", "#E7D217", "#E7D019", "#E7CF1B", "#E7CE1D", "#E7CD1F", "#E7CB21", "#E7CA22", "#E7C924", "#E8C826", "#E8C728", "#E8C62A", "#E8C52B", "#E8C42D", "#E8C32F", "#E8C231", "#E8C133", "#E8C035", "#E8BF36", "#E9BE38", "#E9BD3A", "#E9BC3C", "#E9BB3E", "#E9BB40", "#E9BA42", "#E9B943", "#E9B945", "#E9B847", "#E9B749", "#EAB74B", "#EAB64D", "#EAB64F", "#EAB550", "#EAB552", "#EAB454", "#EAB456", "#EAB358", "#EAB35A", "#EAB35C", "#EBB25D", "#EBB25F", "#EBB261", "#EBB263", "#EBB165", "#EBB167", "#EBB169", "#EBB16B", "#EBB16C", "#EBB16E", "#ECB170", "#ECB172", "#ECB174", "#ECB176", "#ECB178", "#ECB17A", "#ECB17C", "#ECB17E", "#ECB27F", "#ECB281", "#EDB283", "#EDB285", "#EDB387", "#EDB389", "#EDB38B", "#EDB48D", "#EDB48F", "#EDB591", "#EDB593", "#EDB694", "#EEB696", "#EEB798", "#EEB89A", "#EEB89C", "#EEB99E", "#EEBAA0", "#EEBAA2", "#EEBBA4", "#EEBCA6", "#EEBDA8", "#EFBEAA", "#EFBEAC", "#EFBFAD", "#EFC0AF", "#EFC1B1", "#EFC2B3", "#EFC3B5", "#EFC4B7", "#EFC5B9", "#EFC7BB", "#F0C8BD", "#F0C9BF", "#F0CAC1", "#F0CBC3", "#F0CDC5", "#F0CEC7", "#F0CFC9", "#F0D1CB", "#F0D2CD", "#F0D3CF", "#F1D5D1", "#F1D6D3", "#F1D8D5", "#F1D9D7", "#F1DBD8", "#F1DDDA", "#F1DEDC", "#F1E0DE", "#F1E2E0", "#F1E3E2", "#F2E5E4", "#F2E7E6", "#F2E9E8", "#F2EBEA", "#F2ECEC", "#F2EEEE", "#F2F0F0", "#F2F2F2"];

        kriging.plot(canvas, grid, [73.4766, 135.088], [18.1055, 53.5693], colors);
        return canvas;
    }

    /**
     * canvas 转字符数据
     */
    public returnImage(canvas: HTMLCanvasElement) {
        return canvas.toDataURL("image/png");
    }

    /**
     * 开启加载
     */
    public startLoading() {
        console.log('223333')
        loadingPluginService.startLoading();
    }

    /**
     * 关闭加载
     */
    public closeLoading() {
        loadingPluginService.closeLoading();
    }
    /**
     * cesium 插值
     */
    public async renderCesium(type: InterpolationType) {
        this.deleteCesium();
        switch (type) {
        case 'TEMPERATURE_CHAIN':
            return this.renderTemperatureCesium();
        case 'WATER_LEVEL_HZ':
            return this.renderWaterLevelCesium();
        }
    }

    /**
     * cesium 温度插值
     */
    public async renderTemperatureCesium() {
        try {
            this.startLoading();
            const dataJson: any = await import('../../map/service/cesium/data/boundsGeo.json');
            layers.cesiumBoundsGeo = await (window as any).cesiumMap.dataSources.add(GeoJsonDataSource.load(dataJson, {
                stroke: Color.HOTPINK,
                fill: Color.PINK.withAlpha(0.1),
                strokeWidth: 1
            }));
            Camera.DEFAULT_VIEW_RECTANGLE = Rectangle.fromDegrees(73.0, 3.0, 135.0, 53.0);
            (window as any).cesiumMap.camera.flyHome(5);
            //插值之前已经计算过一次
            if (layers.temptureLayerCesium) {
                layers.temptureLayerCesium.show = true;
                this.closeLoading();
                return;
            }
            const canvas: HTMLCanvasElement = await this.loadKriging();
            const urlData = this.returnImage(canvas);
            layers.interpolationCesiumLayer = new SingleTileImageryProvider({
                url: urlData,
                rectangle: new Rectangle(
                    CesiumMath.toRadians(73.4766),
                    CesiumMath.toRadians(18.1055),
                    CesiumMath.toRadians(135.088),
                    CesiumMath.toRadians(53.5693)
                )
            });
            layers.temptureLayerCesium = (window as any).cesiumMap.imageryLayers.addImageryProvider(layers.interpolationCesiumLayer);
            layers.temptureLayerCesium.alpha = 0.4;
            this.closeLoading();
        }catch (e) {
            this.closeLoading();
        }
    }

    /**
     * cesium 水质等级差值
     */
    public async renderWaterLevelCesium() {
        console.log('水质等级差值');
    }


    /**
     * 删除温度插值
     */
    public deleteTemperatureCesium() {
        this.closeLoading();
        if (layers.cesiumBoundsGeo) {
            // 申明
            (window as any).cesiumMap.dataSources.remove(layers.cesiumBoundsGeo);
            layers.cesiumBoundsGeo = null;
            const dom: HTMLElement | null = document.getElementById("cesiumCanvasMap");
            if (dom) {
                dom.remove();
            }
        }
        if ( layers.temptureLayerCesium) {
            layers.temptureLayerCesium.show = false;
        }
        if (layers.interpolationCesiumLayer) {
            (window as any).cesiumMap.imageryLayers.remove(layers.interpolationCesiumLayer);
            layers.interpolationCesiumLayer = null;
        }
    }

    /**
     * 删除温度插值
     */
    public deleteWaterLevelCesium() {


    }
    /**
     * 删除 cesium 插值
     */
    public deleteCesium() {
        this.deleteTemperatureCesium();
        this.deleteWaterLevelCesium();

    }

    /************************************  start  ***********************************************************/

    /**
     * 时间处理
     * @param data
     */
    public mapEvent(data: any) {
        console.log('地图事件处理');
        console.log(data);
        switch (data.action) {
        case 'render':
            if (this.mapType === 'CESIUM') {
                return this.renderCesium(data.data.type);
            }
            if (this.mapType === 'MAPBOX') {
                return this.renderMapbox(data.data.type);
            }
            if (this.mapType === 'LEAFLET') {
                return this.renderLeaflet(data.data.type);
            }
            break;
        case 'delete':
            if (this.mapType === 'CESIUM') {
                return this.deleteCesium();
            }
            if (this.mapType === 'MAPBOX') {
                return this.deleteMapbox();
            }
            if (this.mapType === 'LEAFLET') {
                return this.deleteLeaflet();
            }
        }
    }

    /************************************  end  ***********************************************************/

    /************************************  MapBox  ***********************************************************/
    /************************************  start  ***********************************************************/

    /**
     * mapbox 插值
     */
    public async renderMapbox(type: InterpolationType) {
        this.deleteCesium();
        switch (type) {
        case 'TEMPERATURE_CHAIN':
            return this.renderTemperatureMapbox();
        case 'WATER_LEVEL_HZ':
            return this.renderWaterLevelMapbox();
        }
    }

    /**
     * 渲染全国温度插值
     */
    public async renderTemperatureMapbox() {
        try {
            this.startLoading();
            let urlData = layers.temptureLayerUrlData;
            //插值之前已经计算过一次
            if (!urlData) {
                const canvas: HTMLCanvasElement = await this.loadKriging();
                urlData = this.returnImage(canvas);
                layers.temptureLayerUrlData = urlData;
            }
            // 资源添加
            (window as any).mapboxMap.addSource('kriging', {
                type: 'image',
                url: urlData,
                coordinates: [
                    [73.4766, 53.5693],
                    [135.088, 53.5693],
                    [135.088, 18.1055],
                    [73.4766, 18.1055],
                ],
            });
            (window as any).mapboxMap.setZoom(5);
            // 添加插值图层
            (window as any).mapboxMap.addLayer({
                id: 'kriging',
                type: 'raster',
                source: 'kriging',
                paint: {
                    'raster-opacity': 1,
                },
            });
            (window as any).mapboxMap.fitBounds([ [73.4766, 53.5693],  [135.088, 18.1055]]);
            this.closeLoading();
        }catch (e) {
            this.closeLoading();
        }
    }

    /**
     * 杭州水质等级差值
     */
    public renderWaterLevelMapbox() {

    }
    /**
     * 删除 mapbox 插值
     */
    public deleteMapbox() {
        this.deleteTemperatureMapbox();
        this.deleteWaterLevelMapbox();

    }

    /**
     * 移除温度插值资源、图层
     */
    public deleteTemperatureMapbox() {
        if ((window as any).mapboxMap && (window as any).mapboxMap.getLayer('kriging')) {
            (window as any).mapboxMap.removeLayer('kriging');
            (window as any).mapboxMap.removeSource('kriging');
        }

    }

    /**
     * 移除水质等级差值mapbox
     */
    public deleteWaterLevelMapbox() {

    }


    /************************************  end  ***********************************************************/
    /************************************  leaflet  ***********************************************************/
    /************************************  start  ***********************************************************/
    /**
     * Leaflet 插值
     */
    public async renderLeaflet(type: InterpolationType) {
        this.deleteCesium();
        switch (type) {
        case 'TEMPERATURE_CHAIN':
            return this.renderTemperatureLeaflet();
        case 'WATER_LEVEL_HZ':
            return this.renderWaterLevelLeaflet();
        }
    }

    /**
     * 渲染全国温度插值
     */
    public async renderTemperatureLeaflet() {
        try {
            this.startLoading();
            let urlData = layers.temptureLayerUrlData;
            //插值之前已经计算过一次
            if (!urlData) {
                const canvas: HTMLCanvasElement = await this.loadKriging();
                urlData = this.returnImage(canvas);
                layers.temptureLayerUrlData = urlData;
            }
            const imageBounds = [[53.5693, 73.4766 ], [18.1055, 135.088]] as LatLngBoundsExpression;
            layers.interpolationLeafletLayer = L.imageOverlay(urlData, imageBounds, { opacity: 0.8 }) as any;
            (window as any).leafletMap.addLayer(layers.interpolationLeafletLayer);
            (window as any).leafletMap.fitBounds([ [73.4766, 53.5693],  [135.088, 18.1055]]);
            this.closeLoading();
        }catch (e) {
            this.closeLoading();
        }
    }

    /**
     * 杭州水质等级差值
     */
    public renderWaterLevelLeaflet() {

    }
    /**
     * 删除 mapbox 插值
     */
    public deleteLeaflet() {
        this.deleteTemperatureLeaflet();
        this.deleteWaterLevelLeaflet();

    }

    /**
     * 移除温度插值资源、图层
     */
    public deleteTemperatureLeaflet() {
        if ((window as any).leafletMap && (window as any).leafletMap.hasLayer(layers.interpolationLeafletLayer)) {
            (window as any).leafletMap.removeLayer(layers.interpolationLeafletLayer);
            layers.interpolationLeafletLayer = null;
        }


    }

    /**
     * 移除水质等级差值mapbox
     */
    public deleteWaterLevelLeaflet() {

    }
    /************************************  end  ***********************************************************/

    public beforeDestroy() {
        try {
            this.deleteCesium();
            this.deleteMapbox();
            this.deleteLeaflet();
            layers = {
                cesiumBoundsGeo: null,
                interpolationCesiumLayer: null,   // cesium 温度插值图层
                temptureLayerCesium: null, // cesium 温度插值

                mapboxBoundsGeo: null,
                interpolationMapboxLayer: null,   // cesium 温度插值图层
                temptureLayerMapbox: null, // cesium 温度插值
                interpolationLeafletLayer: null,

                temptureLayerUrlData: null
            };
        }catch (e) {
            console.warn(e);
        }


    }
}
</script>

<style scoped lang="stylus">
.pug-container
    height 100%
    width 100%
</style>
